package cn.kgcnews.controller;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.alibaba.fastjson.JSON;

import cn.kgcnews.pojo.NewsDetail;
import cn.kgcnews.service.NewsService;
import cn.kgcnews.service.UserService;
import cn.kgcnews.service.impl.NewsServiceImpl;
import cn.kgcnews.service.impl.UserServiceImpl;

public class JsonNewsServlet extends HttpServlet {

	
	private static final long serialVersionUID = 1L;


	public void destroy() {
		super.destroy(); // Just puts "destroy" string in log
		// Put your code here
	}

	
	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {

		response.setContentType("text/html;charset=utf-8");
		PrintWriter out = response.getWriter();
		
		NewsService ns=new NewsServiceImpl();
		List<NewsDetail> list = ns.printNewsListTop14();
		//响应json格式的数据
		out.print(JSON.toJSONString(list));
		out.flush();
		out.close();
	}

	
	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {

		this.doGet(request, response);
	}

	public void init() throws ServletException {
		// Put your code here
	}

}
